package jumpingnotes.model.entity;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import net.jf.lucene.analysis.mmseg.MMSegAnalyzer;

import org.hibernate.search.annotations.Analyzer;
import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.Store;

@Entity
@Table(name = "group_topic", catalog = "jumping_notes")
@Indexed
@Analyzer(impl = MMSegAnalyzer.class)
public class GroupTopic implements java.io.Serializable
{

	private Integer groupTopicId;
	private Group group;
	private Member member;
	private String title;
	private String body;
	private Integer status;
	private Integer commentCount;
	private Date createTime;
	private Date updateTime;
	private Set<GroupTopicComment> groupTopicComments = new HashSet<GroupTopicComment>(0);

	public GroupTopic()
	{
	}

	public GroupTopic(Group group, Member member, String title, String body, Date createTime, Date updateTime)
	{
		this.group = group;
		this.member = member;
		this.title = title;
		this.body = body;
		this.createTime = createTime;
		this.updateTime = updateTime;
	}

	public GroupTopic(Group group, Member member, String title, String body, Integer status, Integer commentCount,
			Date createTime, Date updateTime, Set<GroupTopicComment> groupTopicComments)
	{
		this.group = group;
		this.member = member;
		this.title = title;
		this.body = body;
		this.status = status;
		this.commentCount = commentCount;
		this.createTime = createTime;
		this.updateTime = updateTime;
		this.groupTopicComments = groupTopicComments;
	}

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "group_topic_id", unique = true, nullable = false)
	@DocumentId
	public Integer getGroupTopicId()
	{
		return this.groupTopicId;
	}

	public void setGroupTopicId(Integer groupTopicId)
	{
		this.groupTopicId = groupTopicId;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "group_id", nullable = false)
	public Group getGroup()
	{
		return this.group;
	}

	public void setGroup(Group group)
	{
		this.group = group;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "member_id", nullable = false)
	public Member getMember()
	{
		return this.member;
	}

	public void setMember(Member member)
	{
		this.member = member;
	}

	@Column(name = "title", nullable = false)
	@Field(index = Index.TOKENIZED, store = Store.NO)
	public String getTitle()
	{
		return this.title;
	}

	public void setTitle(String title)
	{
		this.title = title;
	}

	@Column(name = "body", nullable = false, length = 65535)
	@Field(index = Index.TOKENIZED, store = Store.NO)
	public String getBody()
	{
		return this.body;
	}

	public void setBody(String body)
	{
		this.body = body;
	}

	@Column(name = "status")
	public Integer getStatus()
	{
		return this.status;
	}

	public void setStatus(Integer status)
	{
		this.status = status;
	}

	@Column(name = "comment_count")
	public Integer getCommentCount()
	{
		return this.commentCount;
	}

	public void setCommentCount(Integer commentCount)
	{
		this.commentCount = commentCount;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "create_time", nullable = false, length = 19)
	public Date getCreateTime()
	{
		return this.createTime;
	}

	public void setCreateTime(Date createTime)
	{
		this.createTime = createTime;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "update_time", nullable = false, length = 19)
	public Date getUpdateTime()
	{
		return this.updateTime;
	}

	public void setUpdateTime(Date updateTime)
	{
		this.updateTime = updateTime;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "groupTopic")
	public Set<GroupTopicComment> getGroupTopicComments()
	{
		return this.groupTopicComments;
	}

	public void setGroupTopicComments(Set<GroupTopicComment> groupTopicComments)
	{
		this.groupTopicComments = groupTopicComments;
	}

}
